enum GameState{ Moving, Shooting, Waiting, Launching, NextLocation }

var mainState : GameState = GameState.Moving;

var sp : SplineController = null;
var lm : LaunchManager = null;
var cc: CheckpointController = null;
var tm : CountDownTimer = null;
var cState : CheckpointControllerState;
var lState : LMState;


function Start(){
  
  var gameobject = GameObject.Find("Player");
   // (ScriptName is the name of the javascript file)
  sp = gameobject.GetComponent("SplineController");
  tm = gameobject.GetComponent("CountDownTimer");
  
  var gameobject1 = GameObject.Find("LaunchManager1");
  lm = gameobject1.GetComponent("LaunchManager");
  
  var gameobject2 = GameObject.Find("Checkpoints");
  cc = gameobject2.GetComponent("CheckpointController");
  
  lm.setStateInactive();
  
  mainState = GameState.Moving;
}

function Update (){
      cState = cc.getState();
      lState = lm.getState();
   switch(mainState){
    case GameState.Moving:
      StartCoroutine(StateActionMoving());
      break;
    case GameState.Shooting:
      StartCoroutine(StateActionShooting());
      break;
    case GameState.Launching:
      //StartCoroutine(StateActionLaunching());
      StateActionLaunching();
      break;
    case GameState.NextLocation:
      StateActionNextLocation();
      break;
    case GameState.Waiting:
        
    break;
    default:
      Debug.Log("Something went wrong");
      Debug.Log(mainState);
      break;
  }
}

function StateActionMoving(){
  //Debug.Log("in StateActionMoving");
  mainState = GameState.Waiting;
  cc.StartMotion();
  yield WaitForSeconds (3);
  //mainState = GameState.Shooting;
  mainState = GameState.NextLocation;
}

function StateActionShooting(){
  //Debug.Log("in StateActionShooting");
  mainState = GameState.Waiting; 
  lm.setStateActive();
  lState = lm.getState();
  yield WaitForSeconds (.25);
  

  mainState = GameState.Launching;
}

function StateActionLaunching(){
  if(lState == LMState.Launching){
    //yield;
  }
  if(lState == LMState.Inactive){
      mainState = GameState.Moving;
  }
}

function StateActionNextLocation(){
  if(cState == CheckpointControllerState.PlayerAtCheckPoint && cc.getPauseSetting){
      lm = cc.GetLaunchMngr();
      mainState = GameState.Shooting;
  }
}